package demo.practice.backtrack;

import java.util.ArrayList;
import java.util.List;

public class Ms0804 {

    public static void main(String[] args) {
        Ms0804 ms0804 = new Ms0804();
        ms0804.subsets(new int[]{1, 2, 3});
    }

    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> subsets = subsets(nums, 0);
        subsets.add(new ArrayList<>());
        return subsets;
    }


    public List<List<Integer>> subsets(int[] nums, int index) {
        if (index == nums.length) {
            return new ArrayList<>();
        }

        List<List<Integer>> back = subsets(nums, index + 1);


        List<List<Integer>> res = new ArrayList();
        //res.addAll(back);


        for (List<Integer> li : back) {

            res.add(new ArrayList<>(li));
            li.add(nums[index]);
            res.add(li);
        }


        ArrayList<Integer> li = new ArrayList<>();
        li.add(nums[index]);
        res.add(li);
        return res;
    }
}
